$(document).ready(function() {
  require(["inputdrop", "tree"], function(inputdrop, tree) {
    var current_selected_node_id = "";

    var key;
    $("input[placeholder]").placeholder();

    function view_init() {
      $("#content_div").css("padding", "0");
      $("#pg-content").css("padding", "0");
    }

  
    // 移动终端事件库表格配置
    var list_col = [
      { text: "", name: "t", width: 3, hideSearch: "hide" },
      { text: "事件名称", name: "name", align: "left", width: 30, tip: true },
      { text: "事件说明", name: "name", align: "left", width: 30, tip: true },
      { text: "事件等级", name: "name", align: "left", width: 30, tip: true }
    ];
    var list_oper = [
      { icon: "rh-icon rh-edit", text: "编辑", aclick: open_event_edit_dialog }
    ];
    var configUrl = "api/property/type/list";
    function terminal_event_list(option) {
      g_grid.render($("#table_div1"), {
        header: list_col,
        url: configUrl,
        type: "xd",
        dataKey: "list",
        oper: list_oper,
        operWidth: "60px",
        paramObj: option.paramObj,
        queryBefore: function(paramObj) {
          if (current_selected_node_id != -1) {
            paramObj.categoryId = current_selected_node_id;
          }
        },
        isLoad: option.isLoad,
        maskObj: option.maskObj,
        hasBorder: false,
        hideSearch: true,
        autoHeight: true,
        showCount: true,
        allowCheckBox: true
      });
    }
    $("#anniu").click(function(){
      $("[data-id=check_all]").trigger("click")
    })
    function open_event_edit_dialog(rowData) {
      // 弹出修改框
      $.ajax({
        type: "GET",
        url: "module/base_resource_mant/terminal_event_tpl.html",
        success: function(data) {
          g_dialog.dialog($(data).find("[id=terminal_event_lib_edit_tpl]"), {
            width: "550px",
            init: init,
            initAfter: initAfter,
            title: "移动终端事件",
            saveclick: save_click
          });
        }
      });

      function init(el) {
        if (rowData) {
          el.umDataBind("render", rowData);
        }
      }
      function initAfter(el, saveObj) {
        
      }

      function save_click(el, saveObj) {
        // 校验等级定义是否已填
        if (validateForm($("#update_form"))) {
          xd_ajax_post({
            url: "api/property/type/save",
            paramObj: saveObj,
            maskObj: el,
            successCallBack: function(data) {
              // 关闭对话框
              g_dialog.hide(el);
              // 弹出成功提示
              g_dialog.operateAlert();
              // 重新刷新列表
              terminal_event_list({
                paramObj: {
                  keyword: key,
                  categoryId: current_selected_node_id
                },
                isLoad: true,
                maskObj: "body"
              });
            }
          });
        }
      }
    }
  
    terminal_event_list({
      paramObj: { pageSize: 50 },
      isLoad: true,
      maskObj: "body"
    });
  });
});
